#include "mrp.h"
#include <time.h>

void swi_mr_div(vm_info_t *vm)
{
	//原型： (int32 a, int32 b) -> int32
	int32 a = vmreg(0);
	int32 b = vmreg(1);
	logsysc("mr_div(a=%d, b=%d)", a, b);

	mr_ret(a / b);
}

void swi_mr_mod(vm_info_t *vm){
	//原型： (int32 a, int32 b) -> int32
	int32 a = vmreg(0);
	int32 b = vmreg(1);
	logsysc("mr_mod(a=%d, b=%d)", a, b);

	mr_ret(a % b);
}


//定时器启动
void swi_mr_timerStart(vm_info_t *vm){
	int32 a = vmreg(0);
	mr_ret(mr_timerStart(a));
}

//停止定时器
void swi_mr_timerStop(vm_info_t *vm){
	mr_timerStop();
}

void swi_mr_getTime(vm_info_t *vm){
	mr_ret(mr_getTime(vm));
}

//获取系统日期时间。
int32 swi_mr_getDatetime(vm_info_t *vm){
	
	mr_datetime*datetime = vmreg(0);
	logi("mr_getDatetime()");
	if(!datetime)
		return MR_FAILED;
	
	time_t now;
	struct tm*t;
	
	time(&now);
	t = localtime(&now);
	
	datetime->year = t->tm_year+1900;
	datetime->month = t->tm_mon+1;
	datetime->day = t->tm_mday;
	datetime->hour = t->tm_hour;
	datetime->minute = t->tm_min;
	datetime->second = t->tm_sec;
	
	return MR_SUCCESS;
}


void swi_mr_plat(vm_info_t *vm)
{
	int32 code = vmreg(0);
	int32 param = vmreg(1);
	logi("mr_plat(%d,%d)", code, param);
	mr_ret(mr_plat(vm, code,param));
}

void swi_mr_platEx(vm_info_t *vm)
{
	int32 code = vmreg(0);
	logi("mr_platEx(%d)", code);
	mr_ret(MR_IGNORE);
}

